package com.jy.wms.controller;

import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.WmsAsnEnclosure;
import com.jy.wms.service.WmsAsnEnclosureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: WmsAsnEnclosureController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Liyi
 * @Date Mon Dec 18 15:49:15 CST 2017
 */
@RestController
@RequestMapping("/WmsAsnEnclosure")
@Api(value = "/WmsAsnEnclosure", description = "关于预期到货通知单附件操作")
public class  WmsAsnEnclosureController extends BaseController<WmsAsnEnclosureService,WmsAsnEnclosure> {

    @ApiOperation(value = "预期到货通知单附件管理 预期到货通知单附件列表", response = JSONObject.class, notes = "查询预期到货通知单附件列表")
    @PostMapping(value = "/list/{ssyqdid}")
    public @ResponseBody JSONArray list(@PathVariable("ssyqdid") String ssyqdid) {
        List<WmsAsnEnclosure> list = new ArrayList<WmsAsnEnclosure>();
        JSONArray json = new JSONArray();
        try {
            json = JSONArray.fromObject(baseService.getListByAsnid(ssyqdid));
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

    @ApiOperation(value = "预期到货通知单附件管理 新增预期到货通知单附件",response = JSONObject.class, notes = "新增预期到货通知单附件")
    @PostMapping(value = "/save")
    public @ResponseBody
    JSONObject save(@RequestBody WmsAsnEnclosure entity){
        try {
            baseService.baseInsertSelective(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"新增预期到货通知单附件成功","", JSONObject.fromObject(entity).toString());
        } catch (SucessException e) {
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"新增预期到货通知单附件成功",e.getMessage(),JSONObject.fromObject(entity).toString());
        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(),"新增客户档案基本信息失败",e.getMessage(),"");
        } catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(),"新增客户档案基本信息失败",e.getMessage(),"");
        }
    }

    @ApiOperation(value = "预期到货通知单附件管理 修改预期到货通知单附件",response = JSONObject.class, notes = "修改预期到货通知单附件")
    @PutMapping(value = "/edit")
    public @ResponseBody
    JSONObject edit(@RequestBody WmsAsnEnclosure entity){
        try {
            baseService.baseUpdateByPrimaryKeySelective(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"修改预期到货通知单附件成功","", "");
        } catch (SucessException e) {
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"修改预期到货通知单附件成功",e.getMessage(),"");
        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(),"修改客户档案基本信息失败",e.getMessage(),"");
        } catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(),"修改客户档案基本信息失败",e.getMessage(),"");
        }
    }

    @ApiOperation(value = "预期到货通知单附件管理 批量删除预期到货通知单附件",response = JSONObject.class, notes = "批量删除预期到货通知单附件")
    @PostMapping(value = "/del")
    public @ResponseBody
    JSONObject del(@RequestBody SetAndModifyModel setAndModifyModel){
        try {
            baseService.baseDeleteBathPrimaryKeys(setAndModifyModel.getIds());
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"删除预期到货通知单附件成功","", "");
        } catch (SucessException e) {
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"删除预期到货通知单附件成功",e.getMessage(),"");
        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(),"删除客户档案基本信息失败",e.getMessage(),"");
        } catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(),"删除客户档案基本信息失败",e.getMessage(),"");
        }
    }

}
